package edu.gzy.rpsm_property.mapper;

import com.github.pagehelper.Page;
import edu.gzy.rpsm_property.pojo.User;
import edu.gzy.rpsm_property.pojo.vo.UnpaidOwner;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Repository
public interface UserMapper {
    @Insert("insert into user value (NULL, #{account}, #{password}, #{idcard}, #{username}, " +
            "#{gender}, #{age}, #{user_type}, #{user_status}, #{user_roomid})")
    int insertUser(User user);

    Page<User> owners();

    @Update("update user set user_status = #{user_status} where userid = #{userid}")
    int changeUserStatus(User user);

    @Select("select * from user where userid = #{userid}")
    User queryById(int id);

    @Select("SELECT a.amount_date, a.amount, `user`.userid, `user`.username, room.room_code " +
            "FROM (SELECT * FROM amount WHERE amount.isPaied = 2 AND amount.amount_type = #{typeId}) AS a " +
            "LEFT JOIN room ON a.amount_roomid = room.room_id " +
            "LEFT JOIN `user` ON room.room_id = `user`.user_roomid " +
            "ORDER BY a.amount_date ASC, `user`.username")
// 引用已经定义的 ResultMap
    @ResultMap("edu.gzy.rpsm_property.mapper.UserMapper.unpaidOwner")
    Page<UnpaidOwner> unpaidOwnerList(Integer typeId);
    @Select("select * from user where idcard = #{idcard}")
    User queryByIdcard(String idcard);
}
